package com.example.config;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @PackageName:com.example.config
 * @className:LoginInterceptor
 * @Description: 登录拦截器
 * @author:朱楚利
 * @date:2021/5/11 13:53
 */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object attribute = request.getSession().getAttribute("USER_LOGIN");
        if(attribute == null){
            request.setAttribute("msg","你还没有登录，没有权限访问");
            request.getRequestDispatcher("/index.html").forward(request,response);
            return false;
        }
        return true;
    }
}
